home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / windownt / winner.zip / WINNER.C < prev    next >
C/C++ Source or Header  |  1992-10-30  |  32KB  |  890 lines

  1.  
  2. /*        Winner        version 1.07.06        for Windows NT     10/28/92        */
  3.  
  4. #include "windows.h"
  5. #include "drivinit.h"
  6. #include "winner.h"
  7. #include "commdlg.h"
  8. #include "io.h"
  9. #include "shellapi.h"
  10. #include "stdio.h"
  11. #include "string.h"
  12. #include <sys\types.h>
  13. #include <sys\stat.h>
  14.  
  15. FARPROC lpAbortDlg, lpAbortProc;
  16.  
  17. CHOOSEFONT cf;
  18. LOGFONT lf;
  19. OFSTRUCT OfStruct;
  20. OPENFILENAME ofn;
  21. PAINTSTRUCT ps;
  22. PLOGFONT plf;
  23. PRINTDLG pd;
  24. RECT Rect;
  25. TEXTMETRIC TextMetric;
  26. HANDLE hAccTable;
  27. HANDLE hEditBuffer;
  28. HANDLE hNewFile;
  29. HANDLE hHourGlass;
  30. HANDLE hInst;
  31. HANDLE hNewBuffer;
  32. HANDLE hOldBuffer;
  33. HANDLE hPrevRunning;
  34. HANDLE hSaveCursor;
  35. HANDLE hShell;
  36. HBRUSH hBkBrush;
  37. HDC hDC;
  38. HDC GetPrinterDC ( void );
  39. HDC hPr;
  40. HFONT hFont;
  41. HFONT hgFont;
  42. HFONT hgWndFont;
  43. HMENU hMenu;
  44. HPEN hPen;
  45. HWND hAbortDlgWnd;
  46. HWND hBtOpenWnd;
  47. HWND hBtOpen2Wnd;
  48. HWND hBtSaveWnd;
  49. HWND hBtSaveasWnd;
  50. HWND hBtDeleteWnd;
  51. HWND hBtPrintWnd;
  52. HWND hBtTypeWnd;
  53. HWND hBtExitWnd;
  54. HWND hBtUndoWnd;
  55. HWND hBtCutWnd;
  56. HWND hBtCopyWnd;
  57. HWND hBtPasteWnd;
  58. HWND hBtClearWnd;
  59. HWND hBtSelaWnd;
  60. HWND hBtFindWnd;
  61. HWND hBtNextWnd;
  62. HWND hBtPrevWnd;
  63. HWND hBtReplWnd;
  64. HWND hBtReplaWnd;
  65. HWND hBtCmplWnd;
  66. HWND hBtBuildWnd;
  67. HWND hBtBuildallWnd;
  68. HWND hBtCleanWnd;
  69. HWND hBtRunWnd;
  70. HWND hBtChelpWnd;
  71. HWND hBtWhelpWnd;
  72. HWND hEditWnd;
  73. HWND hwnd;
  74. BOOL bAbort;
  75. BOOL bButCut = FALSE;
  76. BOOL fCase       = FALSE;
  77. BOOL bChanges = FALSE;
  78. BOOL bSaveEnabled = FALSE;
  79. BOOL bSearchin=FALSE;
  80. DWORD dwEnd;
  81. DWORD dwResults;
  82. DWORD dwLineCount;
  83. DWORD dwStart;
  84. DWORD dwStyle;
  85. DWORD dwStyleEx;
  86. DWORD dwTextColor;
  87. LPSTR lpstrPointer;
  88. PSTR pBuffer;
  89. PSTR pEditBuffer;
  90. WORD wIndex;
  91. WORD wLines;
  92. WORD TabSpacing = 8;
  93. UINT idMenu;
  94. char szBaseWindowTitle[ ] = "Winner";
  95. char szEmptyString[ ] = "";
  96. char szFFileName[MAXFILENAME];
  97. char szFileName[MAXFILENAME] = "";
  98. char szFileTitle[MAXFILENAME];
  99. char szFilterSpec[128] = "All Files (*.*)\0*.*\0Executable (*.EXE)\0*.EXE\0Text Files (*.TXT)\0*.TXT\0";
  100. char szLine[128];
  101. char szRepl[160] = "";
  102. char szSearch[160] = "";
  103. char szTemp[128];
  104. char Untitled[ ] = "Winner - ( untitled )";
  105. char szWindowTitle[80];
  106. char szRepl[ ];
  107. int Count;
  108. int CurrentLine;
  109. int EX = 0;
  110. int EY = 0;
  111. int EW= 640;
  112. int EH= 400;
  113. int hFile;
  114. int Heigth;
  115. int LineLength;
  116. int LinesPerPage;
  117. int LineSpace;
  118. int Response;
  119. int nTabs[1] = {34};
  120. int Width = 0;
  121. struct stat FileStatus;
  122.  
  123. int PASCAL WinMain ( hInstance, hPrevInstance, lpCmdLine, nCmdShow )
  124. HANDLE hInstance;
  125. HANDLE hPrevInstance;
  126. LPSTR lpCmdLine;
  127. int nCmdShow;
  128. {    MSG msg;
  129.     RECT Rect;
  130.     hPrevRunning = FindWindow("WinnerWClass", NULL);
  131.     if ( !hPrevInstance ) {
  132.         WNDCLASS    wc;
  133.         wc.style = NULL;
  134.         wc.lpfnWndProc = MainWndProc;
  135.         wc.cbClsExtra = 0;
  136.         wc.cbWndExtra = 0;
  137.         wc.hInstance = hInstance;
  138.         wc.hIcon = LoadIcon ( hInstance,"Icon" );
  139.         wc.hCursor = LoadCursor ( NULL, IDC_ARROW );
  140.         wc.hbrBackground = GetStockObject ( LTGRAY_BRUSH );
  141.         wc.lpszMenuName = "WinnerMenu";
  142.         wc.lpszClassName = "WinnerWClass";
  143.         if (!RegisterClass ( &wc ) )
  144.             return ( FALSE ) ; }
  145.     if(hPrevRunning) {
  146.         dwTextColor = RGB(0, 0, 128);
  147.         EX = 50 ;
  148.         EY = 25 ; }
  149.     lstrcpy ( (LPSTR)&szFileName,  lpCmdLine ) ;
  150.     if(!lstrcmpi( (LPSTR)&szFileName, "buildres.ult\0")){
  151.         dwTextColor = RGB(128, 0, 0);
  152.         EX=0;
  153.         EY=200;
  154.         EH=280;}
  155.     hInst = hInstance ;
  156.     hAccTable = LoadAccelerators ( hInst, "WinnerAcc" ) ;
  157.     dwStyle = WS_OVERLAPPEDWINDOW ;
  158.     hwnd = CreateWindow ( "WinnerWClass", szBaseWindowTitle, dwStyle, EX, EY, EW-EX, EH, NULL, NULL, hInstance, NULL ) ;
  159.     if ( !hwnd )
  160.         return ( FALSE) ;
  161.     dwStyle = WS_CHILD|WS_VISIBLE|ES_MULTILINE|WS_VSCROLL|WS_HSCROLL|ES_AUTOHSCROLL|ES_AUTOVSCROLL|ES_NOHIDESEL;
  162.     dwStyleEx = WS_EX_TOPMOST ;
  163.     GetClientRect ( hwnd, ( LPRECT) &Rect ) ;
  164.     Width = ( Rect.right - Rect.left ) ;
  165.     Heigth = ( Rect.bottom - Rect.top ) ;
  166.     hEditWnd = CreateWindowEx ( dwStyleEx, "Edit", NULL, dwStyle, 0, 25, Width, Heigth - 25, hwnd, (HMENU)IDC_EDIT, hInst, NULL ) ;
  167.     if ( !hEditWnd ) {
  168.         DestroyWindow ( hwnd ) ;
  169.         return ( NULL ) ; }
  170.     dwStyle = WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_PUSHBUTTON;
  171.     hBtOpenWnd = CreateWindowEx ( dwStyleEx, "Button", "O", dwStyle, 8, 2, 16, 20, hwnd, (HMENU)IDM_OPEN, hInst, NULL );
  172.     hBtOpen2Wnd = CreateWindowEx ( dwStyleEx, "Button", "2", dwStyle, 24, 2, 16, 20, hwnd, (HMENU)IDM_OPEN2, hInst, NULL );
  173.     hBtSaveWnd = CreateWindowEx ( dwStyleEx, "Button", "S", dwStyle, 40, 2, 16, 20, hwnd, (HMENU)IDM_SAVE, hInst, NULL );
  174.     hBtSaveasWnd = CreateWindowEx ( dwStyleEx, "Button", "A", dwStyle, 56, 2, 16, 20, hwnd, (HMENU)IDM_SAVEAS, hInst, NULL );
  175.     hBtDeleteWnd = CreateWindowEx ( dwStyleEx, "Button", "D", dwStyle, 72, 2, 16, 20, hwnd, (HMENU)IDM_DELETE, hInst, NULL );
  176.     hBtPrintWnd = CreateWindowEx ( dwStyleEx, "Button", "P", dwStyle, 88, 2, 16, 20, hwnd, (HMENU)IDM_PRINT, hInst, NULL );
  177.     hBtTypeWnd = CreateWindowEx ( dwStyleEx, "Button", "T", dwStyle, 104, 2, 16, 20, hwnd, (HMENU)IDM_FONTS, hInst, NULL );
  178.     hBtExitWnd = CreateWindowEx ( dwStyleEx, "Button", "X", dwStyle, 120, 2, 16, 20, hwnd, (HMENU)IDM_EXIT, hInst, NULL );
  179.     hBtUndoWnd = CreateWindowEx ( dwStyleEx, "Button", "U", dwStyle, 144, 2, 16, 20, hwnd, (HMENU)IDM_UNDO, hInst, NULL );
  180.     hBtCutWnd = CreateWindowEx ( dwStyleEx, "Button", "C", dwStyle, 160, 2, 16, 20, hwnd, (HMENU)IDM_CUT, hInst, NULL );
  181.     hBtCopyWnd = CreateWindowEx ( dwStyleEx, "Button", ">", dwStyle, 176, 2, 16, 20, hwnd, (HMENU)IDM_COPY, hInst, NULL );
  182.     hBtPasteWnd = CreateWindowEx ( dwStyleEx, "Button", "P", dwStyle, 192, 2, 16, 20, hwnd, (HMENU)IDM_PASTE, hInst, NULL );
  183.     hBtClearWnd = CreateWindowEx ( dwStyleEx, "Button", "D", dwStyle, 208, 2, 16, 20, hwnd, (HMENU)IDM_CLEAR, hInst, NULL );
  184.     hBtSelaWnd = CreateWindowEx ( dwStyleEx, "Button", "A", dwStyle, 224, 2, 16, 20, hwnd, (HMENU)IDM_SELECTALL, hInst, NULL );
  185.     hBtFindWnd = CreateWindowEx ( dwStyleEx, "Button", "F", dwStyle, 248, 2, 16, 20, hwnd, (HMENU)IDM_FIND, hInst, NULL );
  186.     hBtNextWnd = CreateWindowEx ( dwStyleEx, "Button", "N", dwStyle, 264, 2, 16, 20, hwnd, (HMENU)IDM_NEXT, hInst, NULL );
  187.     hBtPrevWnd = CreateWindowEx ( dwStyleEx, "Button", "P", dwStyle, 280, 2, 16, 20, hwnd, (HMENU)IDM_PREV, hInst, NULL );
  188.     hBtReplWnd = CreateWindowEx ( dwStyleEx, "Button", "R", dwStyle, 296, 2, 16, 20, hwnd, (HMENU)IDM_REPL, hInst, NULL );
  189.     hBtReplaWnd = CreateWindowEx ( dwStyleEx, "Button", "A", dwStyle, 312, 2, 16, 20, hwnd, (HMENU)IDM_REPLA, hInst, NULL );
  190.     hBtCmplWnd = CreateWindowEx ( dwStyleEx, "Button", "C", dwStyle, 336, 2, 16, 20, hwnd, (HMENU)IDM_CMPL, hInst, NULL );
  191.     hBtBuildWnd = CreateWindowEx ( dwStyleEx, "Button", "B", dwStyle, 352, 2, 16, 20, hwnd, (HMENU)IDM_BUILD, hInst, NULL );
  192.     hBtBuildallWnd = CreateWindowEx ( dwStyleEx, "Button", "A", dwStyle, 368, 2, 16, 20, hwnd, (HMENU)IDM_BUILDALL, hInst, NULL );
  193.     hBtCleanWnd = CreateWindowEx ( dwStyleEx, "Button", "C", dwStyle, 384, 2, 16, 20, hwnd, (HMENU)IDM_CLEAN, hInst, NULL );
  194.     hBtRunWnd = CreateWindowEx ( dwStyleEx, "Button", "E", dwStyle, 400, 2, 16, 20, hwnd, (HMENU)IDM_RUN, hInst, NULL );
  195.     hBtChelpWnd = CreateWindowEx ( dwStyleEx, "Button", "C", dwStyle, 424, 2, 16, 20, hwnd, (HMENU)IDM_CHELP, hInst, NULL );
  196.     hBtWhelpWnd = CreateWindowEx ( dwStyleEx, "Button", "W", dwStyle, 440, 2, 16, 20, hwnd, (HMENU)IDM_WHELP, hInst, NULL );
  197.     EnableWindow(hBtNextWnd, FALSE);
  198.     EnableWindow(hBtPrevWnd, FALSE);
  199.     EnableWindow(hBtReplWnd, FALSE);
  200.     EnableWindow(hBtCmplWnd, FALSE);
  201.     EnableWindow(hBtBuildWnd, FALSE);
  202.     EnableWindow(hBtBuildallWnd, FALSE);
  203.     SendMessage(hEditWnd, EM_LIMITTEXT, 1048576, 0L);
  204.     hHourGlass = LoadCursor ( NULL, IDC_WAIT ) ;
  205.     hSaveCursor = LoadCursor( NULL, IDC_ARROW ) ;
  206.     ofn.lStructSize = sizeof ( OPENFILENAME ) ;
  207.     ofn.hwndOwner = hwnd ;
  208.     ofn.lpstrFilter     = szFilterSpec ;
  209.     ofn.lpstrCustomFilter = NULL ;
  210.     ofn.nMaxCustFilter = 0 ;
  211.     ofn.nFilterIndex = 1 ;
  212.     ofn.lpstrFile = szFileName ;
  213.     ofn.nMaxFile = MAXFILENAME ;
  214.     ofn.lpstrInitialDir = NULL ;
  215.     ofn.lpstrFileTitle = szFileTitle ;
  216.     ofn.nMaxFileTitle = MAXFILENAME ;
  217.     ofn.lpstrTitle = NULL ;
  218.     ofn.lpstrDefExt = "" ;
  219.     ofn.Flags = 0 ;
  220.     pd.lStructSize = sizeof ( PRINTDLG ) ;
  221.     pd.hwndOwner = hwnd ;
  222.     pd.hDevMode = NULL ;
  223.     pd.hDevNames = NULL ;
  224.     pd.Flags = PD_RETURNDEFAULT;
  225.     pd.nCopies = 1 ;
  226.     strcpy ( lf.lfFaceName, "MS Sans Serif") ;
  227.     lf.lfHeight = 8 ;
  228.     plf = (PLOGFONT) LocalAlloc ( LPTR, sizeof (LOGFONT) ) ;
  229.     plf->lfHeight = lf.lfHeight ;
  230.     strcpy (plf->lfFaceName, lf.lfFaceName ) ;
  231.     hgWndFont = CreateFontIndirect (plf) ;
  232.     SendMessage ( hEditWnd, WM_SETFONT, (WPARAM)hgWndFont, 0L ) ;
  233.     LocalFree ( (HLOCAL) plf );
  234.     ShowWindow ( hwnd, nCmdShow ) ;
  235.     UpdateWindow ( hwnd ) ;
  236.     SendMessage ( hEditWnd, EM_SETTABSTOPS, 1, ( LPARAM )( int far* ) &TabSpacing ) ;
  237.     memset ( &cf, 0, sizeof (CHOOSEFONT ) ) ;
  238.     cf.lStructSize = sizeof ( CHOOSEFONT ) ;
  239.     cf.hwndOwner = hwnd ;
  240.     cf.lpLogFont = &lf ;
  241.     cf.Flags = CF_SCREENFONTS | CF_EFFECTS | CF_INITTOLOGFONTSTRUCT ;
  242.     cf.rgbColors = RGB ( 0, 0, 0 ) ;
  243.     cf.nFontType = SCREEN_FONTTYPE ;
  244.     hMenu = GetMenu (hwnd) ;
  245.     hBkBrush = (HBRUSH)GetStockObject(WHITE_BRUSH);
  246.     if(hPrevRunning) {
  247.         EnableMenuItem ( hMenu, IDM_OPEN2, MF_DISABLED | MF_GRAYED | MF_BYCOMMAND ) ;
  248.         EnableWindow(hBtOpen2Wnd, FALSE);
  249.         cf.rgbColors = RGB ( 0, 0, 255 ); }
  250.     if ( lstrlen (lpCmdLine ) ) {
  251.         PostMessage ( hwnd, WM_COMMAND, IDM_VIEW, 0L) ; }
  252.     while ( GetMessage ( &msg, NULL, NULL, NULL ) ) {
  253.         if ( !TranslateAccelerator ( hwnd, hAccTable, &msg ) ) {
  254.             TranslateMessage ( &msg ) ;
  255.             DispatchMessage ( &msg ) ; } }
  256.     return ( msg.wParam ) ;
  257. }
  258.  
  259. long APIENTRY MainWndProc ( HWND hWnd, UINT uMsg, UINT wParam, LONG lParam )
  260. {    FARPROC lpProcAbout ;
  261.     DWORD FlagSave ;
  262.     DWORD IOStatus ;
  263.     int Status ;
  264.     int nPageSize ;
  265.     switch ( uMsg ) {
  266.         case WM_COMMAND :
  267.             switch ( LOWORD(wParam) ) {
  268.                 case IDM_ABOUT :
  269.                     lpProcAbout = MakeProcInstance ( About, hInst ) ;
  270.                     DialogBox ( hInst, "AboutBox", hWnd, lpProcAbout ) ;
  271.                     FreeProcInstance ( lpProcAbout ) ;
  272.                     break ;
  273.                 case IDM_NEW :
  274.                     if ( !QuerySaveFile ( hWnd ) )
  275.                         return ( NULL ) ;
  276.                     bChanges = FALSE ;
  277.                     szFileName[0] = 0 ;
  278.                     hOldBuffer = ( HANDLE ) SendMessage ( hEditWnd, EM_GETHANDLE, 0, 0L ) ;
  279.                     if ( hOldBuffer ){
  280.                         hNewBuffer = LocalAlloc ( LMEM_MOVEABLE | LMEM_ZEROINIT, 1 );
  281.                         SendMessage ( hEditWnd, EM_SETHANDLE, (WPARAM)hNewBuffer, 0L ) ;
  282.                         SetWindowText ( hWnd, "Winner- Untitled" ) ;
  283.                         SetFocus ( hEditWnd ) ;
  284.                         LocalFree ( hOldBuffer );}
  285.                     break ;
  286.                 case IDM_RUN:
  287.                     sprintf(szFFileName, "%s", szFileName );
  288.                     ofn.nFilterIndex = 2 ;
  289.                     ofn.lpstrTitle="Execute File";
  290.                     if ( !GetOpenFileName ( ( LPOPENFILENAME ) &ofn ) )
  291.                         return ( NULL ) ;
  292.                     ShellExecute ( hWnd, NULL, (LPSTR)&szFileName, "", "", SW_SHOW ) ;
  293.                     sprintf(szFileName, "%s", szFFileName );
  294.                     ofn.nFilterIndex = 1 ;
  295.                     break;
  296.                 case IDM_OPEN2:
  297.                     ofn.nFilterIndex = 1 ;
  298.                     ofn.lpstrTitle="Open 2nd File";
  299.                     sprintf(szFFileName, "%s", szFileName );
  300.                     if ( !GetOpenFileName ( ( LPOPENFILENAME ) &ofn ) )
  301.                         return ( NULL ) ;
  302.                     ShellExecute ( hWnd, NULL, "Winner.exe", (LPSTR)&szFileName, "", SW_SHOW ) ;
  303.                     sprintf(szFileName, "%s", szFFileName );
  304.                     break;
  305.                 case IDM_DELETE :
  306.                     ofn.nFilterIndex = 1 ;
  307.                     ofn.lpstrTitle="Delete File";
  308.                     sprintf(szFFileName, "%s", szFileName );
  309.                     if ( !GetOpenFileName ( ( LPOPENFILENAME ) &ofn ) )
  310.                         return ( NULL ) ;
  311.                     sprintf ( szTemp, "DELETE: %s ?", szFileName ) ;
  312.                     Response = MessageBox ( hWnd, szTemp, "Winner",  MB_YESNOCANCEL | MB_ICONEXCLAMATION ) ;
  313.                     if ( Response == IDYES )
  314.                         DeleteFile ( ( LPSTR )&szFileName ) ;
  315.                     sprintf(szFileName, "%s", szFFileName );
  316.                     break;
  317.                 case IDM_OPEN :
  318.                     if ( !QuerySaveFile ( hWnd ) )
  319.                         return ( NULL ) ;
  320.                     ofn.nFilterIndex = 1 ;
  321.                     ofn.lpstrTitle="Open File";
  322.                     if ( !GetOpenFileName ( ( LPOPENFILENAME ) &ofn ) )
  323.                         return ( NULL ) ;
  324.                 case IDM_VIEW :
  325.                     hFile = OpenFile ( ( LPSTR ) szFileName, ( LPOFSTRUCT )&OfStruct, OF_READ ) ;
  326.                     if ( !hFile )
  327.                         return ( NULL ) ;
  328.                     hOldBuffer = ( HANDLE ) SendMessage ( hEditWnd, EM_GETHANDLE, 0, 0L ) ;
  329.                     LocalFree ( hOldBuffer ) ;
  330.                     dwResults  = GetFileSize((HANDLE)hFile, NULL);
  331.                     hEditBuffer = LocalAlloc ( LMEM_MOVEABLE | LMEM_ZEROINIT, dwResults+1 ) ;
  332.                     if ( !hEditBuffer ) {
  333.                         MessageBox ( hWnd, "Not enough memory.", NULL, MB_OK | MB_ICONEXCLAMATION ) ;
  334.                         close ( hFile ) ;
  335.                         return ( NULL ) ; }
  336.                     hSaveCursor = SetCursor ( hHourGlass ) ;
  337.                     pEditBuffer = LocalLock ( hEditBuffer ) ;
  338.                     ReadFile((HANDLE)hFile, pEditBuffer, dwResults, (LPDWORD)&IOStatus, NULL ) ;
  339.                     close ( hFile ) ;
  340.                     LocalUnlock ( hEditBuffer ) ;
  341.                     if ( IOStatus != dwResults ) {
  342.                         sprintf ( szTemp, "Error reading %s.", szFileName ) ;
  343.                         SetCursor ( hSaveCursor ) ;
  344.                         MessageBox ( hWnd, szTemp, NULL, MB_OK | MB_ICONEXCLAMATION ) ; }
  345.                     sprintf ( szTemp, "%s - %s", szBaseWindowTitle, szFileName ) ;
  346.                     SendMessage ( hEditWnd, EM_SETHANDLE, (WPARAM)hEditBuffer, 0L ) ;
  347.                     SetWindowText ( hWnd, szTemp ) ;
  348.                     SetFocus ( hEditWnd ) ;
  349.                     bChanges = FALSE ;
  350.                     SetCursor ( hSaveCursor ) ;
  351.                     EnableMenuItem ( hMenu, IDM_CMPL, MF_ENABLED | MF_BYCOMMAND ) ;
  352.                     EnableMenuItem ( hMenu, IDM_BUILD, MF_ENABLED | MF_BYCOMMAND ) ;
  353.                     EnableMenuItem ( hMenu, IDM_BUILDALL, MF_ENABLED | MF_BYCOMMAND ) ;
  354.                     EnableWindow(hBtCmplWnd, TRUE);
  355.                     EnableWindow(hBtBuildWnd, TRUE);
  356.                     EnableWindow(hBtBuildallWnd,TRUE);
  357.                     break ;
  358.                 case IDM_SAVE :
  359.                     if ( szFileName[ 0 ] ) {
  360.                         if ( bChanges )
  361.                             SaveFile ( hWnd ) ;
  362.                         SetFocus(hEditWnd);
  363.                         break ; }
  364.                     SetFocus(hEditWnd);
  365.                 case IDM_SAVEAS :
  366.                     ofn.nFilterIndex = 1 ;
  367.                     ofn.lpstrTitle="Save File As";
  368.                     if ( !GetSaveFileName ( ( LPOPENFILENAME ) &ofn ) )
  369.                         return FALSE ;
  370.                     lstrcpy ( szWindowTitle, szBaseWindowTitle ) ;
  371.                     lstrcat ( szWindowTitle, " - " ) ;
  372.                     lstrcat ( szWindowTitle, szFileTitle ) ;
  373.                     SetWindowText ( hWnd, szWindowTitle ) ;
  374.                     SaveFile ( hWnd ) ;
  375.                     break ;
  376.                 case IDM_PRINT :
  377.                     hSaveCursor = SetCursor ( hHourGlass ) ;
  378.                     hPr = GetPrinterDC( ) ;
  379.                     if ( !hPr ) {
  380.                         sprintf ( szTemp, "Cannot print %s", szFileName ) ;
  381.                         MessageBox ( hWnd, szTemp, NULL, MB_OK | MB_ICONHAND ) ;
  382.                         return ( NULL ) ; }
  383.                     lpAbortDlg =  MakeProcInstance ( AbortDlg, hInst ) ;
  384.                     lpAbortProc = MakeProcInstance( AbortProc, hInst ) ;
  385.                     SetAbortProc ( hPr, lpAbortProc ) ;
  386.                     plf = ( PLOGFONT ) LocalAlloc ( LPTR, sizeof ( LOGFONT ) ) ;
  387.                     plf->lfHeight = -MulDiv ( lf.lfHeight, GetDeviceCaps ( hPr, LOGPIXELSY ), 72 ) ;
  388.                     plf->lfWeight = lf.lfWeight ;
  389.                     plf->lfItalic = lf.lfItalic ;
  390.                     plf->lfUnderline = lf.lfUnderline ;
  391.                     plf->lfStrikeOut = lf.lfStrikeOut ;
  392.                     plf->lfCharSet = lf.lfCharSet ;
  393.                     plf->lfQuality = lf.lfQuality ;
  394.                     plf->lfPitchAndFamily = lf.lfPitchAndFamily ;
  395.                     strcpy ( plf->lfFaceName, lf.lfFaceName ) ;
  396.                     hFont = CreateFontIndirect ( plf ) ;
  397.                     SelectObject ( hPr, hFont ) ;
  398.                     if ( Escape ( hPr, STARTDOC, 14, "PrntFile text", ( LPSTR ) NULL ) < 0 ) {
  399.                         MessageBox ( hWnd, "Unable to start print job", NULL, MB_OK | MB_ICONHAND ) ;
  400.                         FreeProcInstance ( lpAbortDlg ) ;
  401.                         FreeProcInstance ( lpAbortProc ) ;
  402.                         DeleteDC ( hPr ) ; }
  403.                     bAbort = FALSE ;
  404.                     hAbortDlgWnd = CreateDialog ( hInst, "AbortDlg", hWnd, lpAbortDlg ) ;
  405.                     if ( !hAbortDlgWnd ) {
  406.                         SetCursor ( hSaveCursor ) ;
  407.                         MessageBox ( hWnd, "NULL Abort window handle", NULL, MB_OK | MB_ICONHAND ) ;
  408.                         return ( FALSE ) ; }
  409.                     ShowWindow ( hAbortDlgWnd, SW_NORMAL ) ;
  410.                     EnableWindow ( hWnd, FALSE ) ;
  411.                     SetCursor ( hSaveCursor ) ;
  412.                     GetTextMetrics ( hPr, &TextMetric ) ;
  413.                     LineSpace = TextMetric.tmHeight + TextMetric.tmExternalLeading ;
  414.                     nPageSize = GetDeviceCaps ( hPr, VERTRES ) ;
  415.                     LinesPerPage = nPageSize / LineSpace - 2 ;
  416.                     wLines = ( WORD ) SendMessage ( hEditWnd, EM_GETLINECOUNT, 0, 0L ) ;
  417.                     CurrentLine = 1 ;
  418.                     dwStyle = 1 ;
  419.                     StartPage ( hPr ) ;
  420.                     Count = sprintf ( szTemp, "File Name  %s     Page  %lu ", szFileName, dwStyle ) ;
  421.                     TextOut ( hPr, 99, CurrentLine*LineSpace, ( LPSTR ) szTemp, Count ) ;
  422.                     CurrentLine ++ ;
  423.                     TextOut ( hPr, 0, CurrentLine*LineSpace, "", NULL ) ;
  424.                     CurrentLine ++ ;
  425.                     for ( wIndex = Status = 0; wIndex < wLines; wIndex++ ) {
  426.                         szLine[0] = 127 ;
  427.                         szLine[1] = 0 ;
  428.                         LineLength = ( int ) SendMessage ( hEditWnd, EM_GETLINE, wIndex, ( DWORD ) ( LPSTR ) szLine ) ;
  429.                         TabbedTextOut ( hPr, 99, CurrentLine*LineSpace, ( LPSTR ) szLine, LineLength, 1,  nTabs, 99 ) ;
  430.                         if ( ++CurrentLine > LinesPerPage ) {
  431.                             CurrentLine = 1 ;
  432.                             dwStyle ++ ;
  433.                             Status = EndPage ( hPr ) ;
  434.                             if ( Status < 0 || bAbort )
  435.                                 break ;
  436.                             SelectObject ( hPr, hFont ) ;
  437.                             StartPage ( hPr ) ;
  438.                             Count = sprintf ( szTemp, "File Name  %s      Page  %lu ", szFileName, dwStyle ) ;
  439.                             TextOut ( hPr, 99, CurrentLine*LineSpace, ( LPSTR ) szTemp, Count ) ;
  440.                             CurrentLine ++ ;
  441.                             TextOut ( hPr, 0, CurrentLine*LineSpace, "", NULL ) ;
  442.                             CurrentLine ++ ; } }
  443.                     if ( Status >= 0 && !bAbort ) {
  444.                         Escape( hPr, NEWFRAME, 0, 0L, 0L ) ;
  445.                         Escape( hPr, ENDDOC, 0, 0L, 0L ) ; }
  446.                     EnableWindow ( hWnd, TRUE ) ;
  447.                     DestroyWindow ( hAbortDlgWnd ) ;
  448.                     FreeProcInstance ( lpAbortDlg ) ;
  449.                     FreeProcInstance ( lpAbortProc ) ;
  450.                     LocalFree ( ( HLOCAL ) plf ) ;
  451.                     DeleteObject ( hFont ) ;
  452.                     DeleteDC ( hPr ) ;
  453.                     break ;
  454.                 case IDM_PRINTSETUP :
  455.                     FlagSave = pd.Flags ;
  456.                     pd.Flags = PD_RETURNDC | PD_PRINTSETUP ;
  457. /*                    PrintDlg ( ( LPPRINTDLG ) &pd ) ;    */
  458. /*                    pd.Flags = FlagSave ;    */
  459.                     break ;
  460.                 case IDM_UNDO :
  461.                     SendMessage ( hEditWnd,EM_UNDO,0,0L ) ;
  462.                     SetFocus(hEditWnd);
  463.                     break ;
  464.                 case IDM_CUT :
  465.                     SendMessage ( hEditWnd, WM_CUT, 0, 0L ) ;
  466.                     SetFocus(hEditWnd);
  467.                     break ;
  468.                 case IDM_COPY :
  469.                     SendMessage ( hEditWnd, WM_COPY, 0, 0L ) ;
  470.                     SendMessage ( hEditWnd, EM_GETSEL, (WPARAM)(LPDWORD)&dwStart, 0L ) ;
  471.                     SendMessage ( hEditWnd, EM_SETSEL, (WPARAM)dwStart, (LPARAM)dwStart ) ;
  472.                     SetFocus(hEditWnd);
  473.                     break ;
  474.                 case IDM_PASTE :
  475.                     SendMessage ( hEditWnd, WM_PASTE, 0, 0L ) ;
  476.                     SetFocus(hEditWnd);
  477.                     break ;
  478.                 case IDM_CLEAR :
  479.                     SendMessage ( hEditWnd, WM_CLEAR, 0, 0L ) ;
  480.                     break ;
  481.                 case IDM_SELECTALL :
  482.                     SendMessage ( hEditWnd, EM_SETSEL, 0, -1 ) ;
  483.                     break ;
  484.                 case IDM_CMPL:
  485.                     if ( !QuerySaveFile ( hWnd ) )
  486.                         return ( NULL ) ;
  487.                     ShellExecute ( hWnd, NULL, "winner.bat", szFileName,"", SW_MINIMIZE ) ;
  488.                     break ;                    
  489.                 case IDM_BUILD :
  490.                     if ( !QuerySaveFile ( hWnd ) )
  491.                         return ( NULL ) ;
  492.                     ShellExecute ( hWnd, NULL, "winner.bat", " b", "", SW_MINIMIZE ) ;
  493.                     break ;
  494.                 case IDM_BUILDALL :
  495.                     if ( !QuerySaveFile ( hWnd ) )
  496.                         return ( NULL ) ;
  497.                     ShellExecute ( hWnd, NULL, "winner.bat", " a", "", SW_MINIMIZE ) ;
  498.                     break ;
  499.                 case IDM_CLEAN :
  500.                     ShellExecute ( hWnd, NULL, "winner.bat", " c", "" ,SW_MINIMIZE ) ;
  501.                     break ;
  502.                 case IDM_FIND :
  503.                     EnableMenuItem ( hMenu, IDM_NEXT, MF_ENABLED | MF_BYCOMMAND ) ;
  504.                     EnableWindow(hBtNextWnd, TRUE);
  505.                     EnableMenuItem ( hMenu, IDM_PREV, MF_ENABLED | MF_BYCOMMAND ) ;
  506.                     EnableWindow(hBtPrevWnd, TRUE);
  507.                     EnableMenuItem ( hMenu, IDM_REPL, MF_ENABLED | MF_BYCOMMAND ) ;
  508.                     EnableWindow(hBtReplWnd, TRUE);
  509.                     Find( ) ;
  510.                     break ;
  511.                 case IDM_NEXT :
  512.                     FindNext( ) ;
  513.                     SetFocus(hEditWnd);
  514.                     break ;
  515.                 case IDM_PREV :
  516.                     FindPrev( ) ;
  517.                     SetFocus(hEditWnd);
  518.                     break ;
  519.                 case IDM_REPL :
  520.                     SendMessage ( hEditWnd, EM_REPLACESEL, 0, ( LPARAM ) ( LPSTR ) &szRepl ) ;
  521.                     SetFocus(hEditWnd);
  522.                     break ;
  523.                 case IDM_REPLA :
  524.                     bSearchin = TRUE ;
  525.                     SendMessage ( hEditWnd, EM_SETSEL, 0, 0L ) ;
  526.                     Find( ) ;
  527.                     while ( bSearchin ) {
  528.                         bSearchin = FALSE ;
  529.                         dwResults = SendMessage ( hEditWnd, EM_GETSEL, 0, 0L ) ;
  530.                         if ( dwResults != 0 ) {
  531.                             SendMessage ( hEditWnd, EM_REPLACESEL, 0, ( LPARAM ) ( LPSTR ) &szRepl ) ;
  532.                             bSearchin = TRUE ;
  533.                             FindNext( ) ; } }
  534.                     break ;
  535.                 case IDM_FONTS :
  536.                     if (ChooseFont (&cf)) {
  537.                         plf = (PLOGFONT) LocalAlloc ( LPTR, sizeof (LOGFONT) ) ;
  538.                         plf->lfHeight = lf.lfHeight ;
  539.                         plf->lfWeight = lf.lfWeight ;
  540.                         plf->lfItalic = lf.lfItalic ;
  541.                         plf->lfUnderline = lf.lfUnderline ;
  542.                         plf->lfStrikeOut = lf.lfStrikeOut ;
  543.                         plf->lfCharSet = lf.lfCharSet ;
  544.                         plf->lfQuality = lf.lfQuality ;
  545.                         plf->lfPitchAndFamily = lf.lfPitchAndFamily ;
  546.                         strcpy (plf->lfFaceName, lf.lfFaceName ) ;
  547.                         dwTextColor = cf.rgbColors ;
  548.                         hgFont = CreateFontIndirect (plf) ;
  549.                         SendMessage ( hEditWnd, WM_SETFONT, (WPARAM)hgFont, 0L ) ;
  550.                         LocalFree ( (HLOCAL) plf ); }
  551.                     break ;
  552.                 case IDM_EXIT :
  553.                     QuerySaveFile ( hWnd ) ;
  554.                     DestroyWindow ( hWnd ) ;
  555.                     break ;
  556.                 case IDM_CHELP:
  557.                     ShellExecute ( hWnd, NULL, "winhlp32.exe", " tools.hlp", "", SW_SHOW ) ;
  558.                     break;
  559.                 case IDM_WHELP:
  560.                     ShellExecute ( hWnd, NULL, "winhlp32.exe", " api32wh.hlp", "", SW_SHOW ) ;
  561.                     break;
  562.                 case IDC_EDIT :
  563.                     if ( HIWORD ( wParam ) == EN_CHANGE ) {
  564.                         bChanges = TRUE ;
  565.                         SendMessage ( hEditWnd, EM_GETSEL, (WPARAM)(LPDWORD)&dwStart, 0L ) ;
  566.                         dwResults = SendMessage ( hEditWnd, EM_LINEFROMCHAR,dwStart,0L ) ;
  567.                         if ( dwResults == dwLineCount )
  568.                             break ;
  569.                         dwLineCount = sprintf ( szTemp, "Line Number  %u    ", dwResults+1 ) ;
  570.                         hDC = GetDC(hwnd);
  571.                         SetBkColor(hDC, (COLORREF)RGB(192, 192, 192));
  572.                         SelectObject(hDC, hgWndFont);
  573.                         TextOut(hDC, 472, 5, (LPSTR)&szTemp, dwLineCount) ;
  574.                         ReleaseDC(hwnd, hDC);
  575.                         dwLineCount = dwResults ;
  576.                         if(bButCut) {
  577.                             bButCut = FALSE;
  578.                             break;}
  579.                         TabSpacing =  (WORD)dwResults ;
  580.                         dwResults = SendMessage ( hEditWnd, EM_GETLINE, (WPARAM)TabSpacing, ( DWORD ) ( LPSTR ) szTemp ) ;
  581.                         if ( dwResults == 0 ) {
  582.                             dwResults = SendMessage ( hEditWnd, EM_GETLINE, (WPARAM)TabSpacing - 1, ( DWORD ) ( LPSTR ) szTemp ) ;
  583.                             lpstrPointer = ( LPSTR ) szTemp ;
  584.                             TabSpacing = 0 ;
  585.                             while ( *lpstrPointer == ( BYTE ) 9 ) {
  586.                                 TabSpacing ++ ;
  587.                                 lpstrPointer ++ ; }
  588.                             lpstrPointer = ( LPSTR ) szTemp + dwResults -1 ;
  589.                             if ( *lpstrPointer == ( BYTE ) 40 )
  590.                                 TabSpacing++ ;
  591.                             if ( *lpstrPointer == ( BYTE ) 41 )
  592.                                 TabSpacing++ ;
  593.                             if ( *lpstrPointer == ( BYTE ) 58 )
  594.                                 TabSpacing++ ;
  595.                             if ( *lpstrPointer == ( BYTE ) 123 )
  596.                                 TabSpacing++ ;
  597.                             if ( TabSpacing > 0 )
  598.                                 if ( *lpstrPointer == ( BYTE ) 125 )
  599.                                     TabSpacing-- ;
  600.                             wsprintf ( szTemp, "" ) ;
  601.                             while ( TabSpacing >0 ) {
  602.                                 lstrcat ( szTemp, "\t" ) ;
  603.                                 TabSpacing-- ; }
  604.                             SendMessage ( hEditWnd, EM_REPLACESEL, 0, ( LPARAM ) ( LPSTR ) szTemp ) ; }
  605.                         break ; }
  606.                     if ( HIWORD ( wParam ) == EN_ERRSPACE ) {
  607.                         MessageBox ( GetFocus ( ), "Out of memory.", "PrntFile Sample Application", MB_ICONHAND | MB_OK ) ; }
  608.                     break ; }
  609.                 break ;
  610.         case WM_PAINT:
  611.             hDC = BeginPaint(hwnd, (LPPAINTSTRUCT)&ps);
  612.             MoveToEx(hDC, 0, 24, NULL);
  613.             hPen = SelectObject(hDC, (HGDIOBJ)GetStockObject(BLACK_PEN));
  614.             LineTo(hDC, 632, 24);
  615.             MoveToEx(hDC, 466, 20, NULL);
  616.             DeleteObject(hPen);
  617.             hPen = SelectObject(hDC, (HGDIOBJ)CreatePen(PS_SOLID, 2, RGB(128,128,128)));
  618.             LineTo(hDC, 466, 3);
  619.             LineTo(hDC, 620, 3);
  620.             LineTo(hDC, 620, 4);
  621.             DeleteObject(hPen);
  622.             hPen = SelectObject(hDC, (HGDIOBJ)CreatePen(PS_SOLID, 2, RGB(255, 255, 255)));
  623.             LineTo(hDC, 620,21);
  624.             LineTo(hDC, 466, 21);
  625.             DeleteObject(hPen);
  626.             dwResults = sprintf ( szTemp, "Line Number  %u    ", dwLineCount+1 ) ;
  627.             SetBkColor(hDC, (COLORREF)RGB(192, 192, 192));
  628.             SelectObject(hDC, hgWndFont);
  629.             TextOut(hDC, 472, 5, (LPSTR)&szTemp, dwResults) ;
  630.             EndPaint(hwnd, (LPPAINTSTRUCT)&ps);
  631.         case WM_CTLCOLOREDIT:
  632.             if (lParam == (LPARAM)hEditWnd) {
  633.                 SetTextColor ( (HDC) wParam, (COLORREF) dwTextColor);
  634.                 return (WPARAM)hBkBrush;}
  635.             return NULL;
  636.         case WM_SETCURSOR :
  637.             if (wParam == (WPARAM)hEditWnd ) {
  638.                 SendMessage(hEditWnd, EM_GETSEL, (WPARAM)(LPDWORD)&dwStart, (LPARAM)(LPDWORD)&dwEnd);
  639.                 if(HIWORD(lParam) == WM_RBUTTONUP) {
  640.                     if(dwEnd == dwStart)
  641.                         SendMessage ( hEditWnd, WM_PASTE, 0, 0L ) ;
  642.                     else {
  643.                         SendMessage ( hEditWnd, WM_CUT, 0, 0L ) ;
  644.                         SendMessage ( hEditWnd, EM_SETSEL, (WPARAM)dwStart, (LPARAM)dwStart ) ;
  645.                         bButCut = TRUE;}}
  646.                 dwResults = SendMessage ( hEditWnd, EM_LINEFROMCHAR, dwStart, 0L ) ;
  647.                 if ( dwResults == dwLineCount )
  648.                     break ;
  649.                 dwLineCount = sprintf ( szTemp, "Line Number  %u    ", dwResults+1 ) ;
  650.                 hDC = GetDC(hwnd);
  651.                 SetBkColor(hDC, (COLORREF)RGB(192, 192, 192));
  652.                 SelectObject(hDC, hgWndFont);
  653.                 TextOut(hDC, 472, 5, (LPSTR)&szTemp, dwLineCount) ;
  654.                 ReleaseDC(hwnd, hDC);
  655.                 dwLineCount=dwResults ;
  656.                 break ; }
  657.             return ( DefWindowProc ( hWnd, uMsg, wParam, lParam ) ) ;
  658.         case WM_SETFOCUS :
  659.             SetFocus ( hEditWnd ) ;
  660.             break ;
  661.         case WM_SIZE :
  662.             MoveWindow ( hEditWnd, 0, 25, LOWORD ( lParam ), HIWORD ( lParam ) - 25, TRUE ) ;
  663.             break ;
  664.         case WM_QUERYENDSESSION :
  665.             return ( QuerySaveFile ( hWnd ) ) ;
  666.         case WM_CLOSE :
  667.             if ( QuerySaveFile ( hWnd ) )
  668.                 DestroyWindow ( hWnd ) ;
  669.             break ;
  670.         case WM_DESTROY :
  671.             PostQuitMessage ( 0 ) ;
  672.             break ;
  673.         default :
  674.             return ( DefWindowProc ( hWnd, uMsg, wParam, lParam ) ) ; }
  675.     return ( NULL ) ;
  676. }
  677.  
  678. BOOL SaveFile ( hWnd )
  679. HWND hWnd ;
  680. {   BOOL bSuccess ;
  681.     DWORD IOStatus ;
  682.     if ( ( hNewFile = CreateFile (szFileName,     GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
  683.                                             NULL, CREATE_ALWAYS, 0, NULL ) ) < 0) {
  684.         sprintf ( szTemp, "Cannot write to %s.", szFileName ) ;
  685.         MessageBox ( hWnd, szTemp, NULL, MB_OK | MB_ICONHAND ) ;
  686.         return ( FALSE ) ; }
  687.     hEditBuffer = ( HANDLE) SendMessage ( hEditWnd, EM_GETHANDLE, 0, 0L ) ;
  688.     pEditBuffer = LocalLock ( hEditBuffer ) ;
  689.     hSaveCursor = SetCursor ( hHourGlass ) ;
  690.      WriteFile (hNewFile, pEditBuffer, strlen ( pEditBuffer ), (LPDWORD)&IOStatus, NULL ) ;
  691.     CloseHandle ( hNewFile ) ;
  692.     SetCursor ( hSaveCursor ) ;
  693.     if ( IOStatus != strlen ( pEditBuffer ) ) {
  694.         sprintf ( szTemp, "Error writing to %s.", szFileName ) ;
  695.         MessageBox ( hWnd, szTemp, NULL, MB_OK | MB_ICONHAND ) ;
  696.         bSuccess = FALSE ; }
  697.     else {
  698.         bSuccess = TRUE ;
  699.         bChanges = FALSE ; }
  700.     LocalUnlock ( hEditBuffer ) ;
  701.     return ( bSuccess ) ;
  702. }
  703.  
  704. BOOL QuerySaveFile ( hWnd )
  705. HWND hWnd ;
  706. {    if ( bChanges ) {
  707.         sprintf ( szTemp, "Save current changes: %s", szFileName ) ;
  708.         Response = MessageBox ( hWnd, szTemp, "Winner",  MB_YESNOCANCEL | MB_ICONEXCLAMATION ) ;
  709.         if ( Response == IDYES ) {
  710.             while ( !szFileName[ 0 ] ) {
  711.                 if ( !GetSaveFileName ( ( LPOPENFILENAME ) &ofn ) )
  712.                     return FALSE ; }
  713.             SaveFile ( hWnd ) ; }
  714.         else if ( Response == IDCANCEL )
  715.             return ( FALSE ) ; }
  716.     else  return ( TRUE ) ;
  717. }
  718.  
  719. HDC GetPrinterDC ( void )
  720. {    HDC         hDC ;
  721.     LPDEVMODE   lpDevMode = NULL ;
  722.     LPDEVNAMES  lpDevNames ;
  723.     LPSTR       lpszDriverName ;
  724.     LPSTR       lpszDeviceName ;
  725.     LPSTR       lpszPortName ;
  726.     if ( !PrintDlg ( ( LPPRINTDLG ) &pd ) )
  727.         return ( NULL ) ;
  728.     if ( pd.hDC )
  729.         hDC = pd.hDC ;
  730.     else {
  731.         if ( !pd.hDevNames )
  732.             return ( NULL ) ;
  733.         lpDevNames = ( LPDEVNAMES ) GlobalLock ( pd.hDevNames ) ;
  734.         lpszDriverName = ( LPSTR ) lpDevNames + lpDevNames->wDriverOffset ;
  735.         lpszDeviceName = ( LPSTR ) lpDevNames + lpDevNames->wDeviceOffset ;
  736.         lpszPortName   = ( LPSTR ) lpDevNames + lpDevNames->wOutputOffset ;
  737.         GlobalUnlock ( pd.hDevNames ) ;
  738.         if ( pd.hDevMode )
  739.             lpDevMode = ( LPDEVMODE ) GlobalLock ( pd.hDevMode ) ;
  740.         hDC = CreateDC ( lpszDriverName, lpszDeviceName, lpszPortName, NULL ) ;
  741.         if ( pd.hDevMode && lpDevMode )
  742.             GlobalUnlock ( pd.hDevMode ) ; }
  743.     if ( pd.hDevNames ) {
  744.         GlobalFree( pd.hDevNames ) ;
  745.         pd.hDevNames = NULL ; }
  746.     if ( pd.hDevMode ) {
  747.         GlobalFree ( pd.hDevMode ) ;
  748.         pd.hDevMode = NULL ; }
  749.     return ( hDC ) ;
  750. }
  751.  
  752. int APIENTRY AbortProc ( hPr, Code )
  753. HDC hPr ;
  754. int Code ;
  755. {    MSG msg ;
  756.     if ( !hAbortDlgWnd )
  757.         return ( TRUE ) ;
  758.     while ( !bAbort && PeekMessage ( &msg, NULL, NULL, NULL, TRUE ) )
  759.            if ( !IsDialogMessage ( hAbortDlgWnd, &msg ) ) {
  760.             TranslateMessage ( &msg ) ;
  761.             DispatchMessage ( &msg ) ; }
  762.     return ( !bAbort ) ;
  763. }
  764.  
  765. int APIENTRY AbortDlg ( HWND hDlg, UINT uMsg, UINT wParam, LONG lParam )
  766. {    switch ( uMsg ) {
  767.         case WM_COMMAND :
  768.             return ( bAbort = TRUE ) ;
  769.         case WM_INITDIALOG :
  770.             SetFocus ( GetDlgItem ( hDlg, IDCANCEL ) ) ;
  771.             SetDlgItemText ( hDlg, IDC_FILENAME, szFileName ) ;
  772.             return ( TRUE ) ; }
  773.     return ( FALSE ) ;
  774. }
  775.  
  776. BOOL APIENTRY About ( HWND hDlg, UINT uMsg, UINT wParam, LONG lParam )
  777. {    switch ( uMsg ) {
  778.         case WM_INITDIALOG :
  779.             return ( TRUE ) ;
  780.         case WM_COMMAND :
  781.             if ( LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL ) {
  782.                 EndDialog( hDlg, TRUE ) ;
  783.                 return ( TRUE ) ; }
  784.             return ( TRUE ) ; }
  785.     return ( FALSE ) ;
  786. }
  787.  
  788. BOOL NEAR PASCAL RealSlowCompare (pSubject, pTarget )
  789. LPSTR pSubject;
  790. LPSTR pTarget;
  791. {    if (fCase){
  792.         while (*pTarget)
  793.             if (*pTarget++ != *pSubject++)
  794.                 return FALSE;}
  795.     else{
  796.         AnsiLower ((LPSTR)pTarget);
  797.         while (*pTarget)
  798.             if (*pTarget++ != (char)(DWORD)AnsiLower ((LPSTR)(DWORD)(BYTE)*pSubject++))
  799.                 return FALSE;}
  800.     return TRUE;
  801. }
  802.  
  803. VOID NEAR PASCAL MyFindText( dch )
  804. LONG dch;
  805. {    DWORD  cch;
  806.     DWORD i;
  807.     if (!*szSearch)
  808.         return;
  809.     SendMessage(hEditWnd, EM_GETSEL,(WPARAM)(LPDWORD)&dwStart, 0L);
  810.     hEditBuffer = (HANDLE)SendMessage (hEditWnd, EM_GETHANDLE, 0, 0L);
  811.     pEditBuffer = LocalLock(hEditBuffer);
  812.     cch = SendMessage (hEditWnd, WM_GETTEXTLENGTH, 0, 0L);
  813.     pEditBuffer += dwStart + dch;
  814.     if (dch < 0)
  815.         i = dwStart;
  816.     else
  817.         i = cch - dwStart + 1 - lstrlen (szSearch);
  818.     while ( i > 0){
  819.         dwStart+=dch;
  820.         if (RealSlowCompare(pEditBuffer, (LPSTR)&szSearch)){
  821.             LocalUnlock(hEditBuffer);
  822.             dwEnd = dwStart + lstrlen (szSearch);
  823.             SendMessage (hEditWnd, EM_SETSEL, dwStart, dwEnd);
  824.             return;}
  825.         i--;
  826.         pEditBuffer += dch;}
  827.     LocalUnlock (hEditBuffer);
  828.     MessageBox (hwnd,"Done","Find String", MB_OK);
  829.     SendMessage(hEditWnd, EM_SETSEL, 0, 0L);
  830.     SetFocus(hEditWnd);
  831.     return;
  832. }
  833.  
  834. VOID FAR PASCAL FindPrev(void)
  835. {    MyFindText(-1);
  836. }
  837.  
  838. VOID FAR PASCAL FindNext(void)
  839. {    MyFindText(1);
  840. }
  841.  
  842. BOOL APIENTRY FindDlgProc(HWND hwnd, UINT uMsg, UINT wParam, LONG lParam)
  843. {    switch (uMsg){
  844.         case WM_INITDIALOG:{
  845.             CheckDlgButton (hwnd, IDD_CASE, fCase);
  846.             SetDlgItemText (hwnd, IDD_SEARCH, szSearch);
  847.             SetDlgItemText (hwnd, IDD_REPL, szRepl);
  848.             if (!lstrlen (szSearch)){
  849.                 EnableWindow (GetDlgItem (hwnd, IDOK), FALSE);
  850.                 EnableWindow (GetDlgItem (hwnd, IDD_PREV), FALSE);}
  851.             break;}
  852.         case WM_COMMAND:{
  853.             int i = 1;
  854.             switch (LOWORD(wParam)){
  855.                 case IDD_SEARCH:
  856.                     if (HIWORD (wParam) == EN_CHANGE){
  857.                         if (! SendDlgItemMessage (hwnd, IDD_SEARCH, WM_GETTEXTLENGTH, 0, 0L))
  858.                             i = FALSE;
  859.                     else
  860.                         i = TRUE;
  861.                     EnableWindow (GetDlgItem (hwnd, IDOK), i);
  862.                     EnableWindow (GetDlgItem (hwnd, IDD_PREV), i);}
  863.                     break;
  864.                 case IDD_CASE:
  865.                     CheckDlgButton (hwnd, IDD_CASE, !IsDlgButtonChecked (hwnd, IDD_CASE));
  866.                     break;
  867.                 case IDD_PREV:
  868.                     i=-1;
  869.                 case IDOK:
  870.                     fCase = IsDlgButtonChecked( hwnd, IDD_CASE);
  871.                     GetDlgItemText (hwnd, IDD_SEARCH, szSearch, sizeof (szSearch));
  872.                     GetDlgItemText (hwnd, IDD_REPL, szRepl, sizeof (szRepl));
  873.                     MyFindText (i);
  874.                 case IDCANCEL:
  875.                     EndDialog (hwnd, 0);
  876.                     break;
  877.                 default:
  878.                     return FALSE;}
  879.             break;}
  880.         default:
  881.             return FALSE;}
  882.     return TRUE;
  883. }
  884.  
  885. VOID FAR PASCAL Find()
  886. {    FARPROC lpfn;
  887.     lpfn = MakeProcInstance (FindDlgProc, hInst);
  888.     DialogBox (hInst,"FindBox", hEditWnd, lpfn);
  889.     FreeProcInstance (lpfn);
  890. }